package training.ui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;

public class SwingUI  {
	JLabel myLabel;
	public void simpleUI(){
		
		JFrame myFrame = new JFrame("Java training");
		
		myFrame.setLayout(new BorderLayout());
		myLabel =new JLabel(" java training is going on");		
		myFrame.getContentPane().add(myLabel, BorderLayout.NORTH);
		
		JButton button1 = new JButton("West");
		myFrame.getContentPane().add(button1, BorderLayout.WEST);

		JButton button2 = new JButton("East");
		myFrame.getContentPane().add(button2, BorderLayout.EAST);

		//JButton button3 = new JButton("South");
		//myFrame.getContentPane().add(button3, BorderLayout.SOUTH);

		
		String items[] ={"first","second","third","fourth"};
		JComboBox myCombo = new JComboBox(items);
		myFrame.getContentPane().add(myCombo, BorderLayout.SOUTH);
		
	//	MyItemListener itemListener = new MyItemListener();
		myCombo.addItemListener(new ItemListener() {
			
			@Override
			public void itemStateChanged(ItemEvent event) {
				
				myLabel.setText("You changed selected item to " +  event.getItem());
			}
		});
		
		
		JCheckBox myCheck = new JCheckBox();
		
		JRadioButton button = new JRadioButton();
		//button.addItemListener(paramItemListener)
	
		
		
		//JRadioButton radioButton = new JRadioButton("My radio");
		
		//radioButton.
		
		
		
		JButton button4 = new JButton("Central Area......");
		myFrame.getContentPane().add(button4, BorderLayout.CENTER);
		
		//myFrame.setLayout(new FlowLayout());
		
		MyButtonListener buttonListener = new MyButtonListener();
		
		button1.addActionListener(buttonListener);
		button2.addActionListener(buttonListener);
		//button3.addActionListener(buttonListener);
		button4.addActionListener(buttonListener);
		
		myFrame.pack();
		//myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		MyWindowListener listener = new MyWindowListener();
		myFrame.addWindowListener(listener);
		myFrame.setVisible(true);
		
		
	}
	class MyItemListener  implements ItemListener {
		
		@Override
		public void itemStateChanged(ItemEvent event) {
			
			myLabel.setText("You changed selected item to " +  event.getItem());
		}
	}
	
	
	class MyButtonListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent event) {
		
			myLabel.setText("You clicked on " + event.getActionCommand() );
			
		}
		
	}
	
	
	class MyWindowListener implements WindowListener {
		
		@Override
		public void windowOpened(WindowEvent arg0) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void windowIconified(WindowEvent arg0) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void windowDeiconified(WindowEvent arg0) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void windowDeactivated(WindowEvent arg0) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void windowClosing(WindowEvent arg0) {
			System.exit(0);
			
		}
		
		@Override
		public void windowClosed(WindowEvent arg0) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void windowActivated(WindowEvent arg0) {
			// TODO Auto-generated method stub
			
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		SwingUI main  = new SwingUI();
		main.simpleUI();

	}

}
